package com.zyf.project.kvdb.protocol.handler;

import com.zyf.project.kvdb.protocol.proto.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.SocketChannel;

/**
 * @author Zhou Yifan
 */
public interface KVDBHandler {

    /**
     * 初始化 Channel
     *
     * @param channel {@link SocketChannel}
     */
    void channel(SocketChannel channel);

    /**
     * 连接成功之后的操作
     *
     * @param channelHandlerContext {@link ChannelHandlerContext}
     * @throws InterruptedException 中断异常
     */
    void connected(ChannelHandlerContext channelHandlerContext) throws InterruptedException;

    /**
     * 断开连接之后的操作
     *
     * @param channelHandlerContext {@link ChannelHandlerContext}
     */
    void disconnected(ChannelHandlerContext channelHandlerContext);

    /**
     * 接收到消息时的操作
     *
     * @param channelHandlerContext {@link ChannelHandlerContext}
     * @param message               {@link Message}
     */
    void receive(ChannelHandlerContext channelHandlerContext, Message message);
}
